package gr.handmademarket.ui.modals;

import gr.handmademarket.po.implementations.Seller;
import gr.handmademarket.po.interfaces.User;
import gr.handmademarket.ui.WebHandMadeSession;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.basic.Label;

/**
 * utility class for modals.
 */
public class ModalUtils {
	
	/**
	 * @param window
	 * @param target
	 */
	@SuppressWarnings("nls")
	public static void closeCallback(ModalWindow window, AjaxRequestTarget target){
		WebHandMadeSession session = (WebHandMadeSession) WebHandMadeSession.get();
		User user = session.getUser();
		if (user != null){
			Label welcomeMessage = new Label("welcomeMsg", "welcome " +  user.getFirstName() + " " + user.getLastName());
			window.getParent().get("welcomeMsg").replaceWith(welcomeMessage);
		}
		window.getParent().get("signInLink").setVisible(user == null);
		window.getParent().get("signUpLink").setVisible(user == null);
		window.getParent().get("signOutLink").setVisible(user != null);
		window.getParent().get("sellerAdminLink").setVisible(user != null && user instanceof Seller);
		target.add(window.getPage());
	}

}
